package com.choosefine.springboot.devops.base.config;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Administrator on 2017/2/20 0020.
 */
public class WXRequestUtil {

    public  static JSONObject getUser(String getUserInfoUrl) throws IOException {
        URL url1 = new URL(getUserInfoUrl);
        HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection();
// 将返回的输入流转换成字符串
        InputStream inputStream = urlConnection.getInputStream();
// 指定编码格式
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
        BufferedReader in = new BufferedReader(inputStreamReader);
        String jsonUserStr =in.readLine().toString();
        System.out.println("jsonUserStr = "+jsonUserStr);
// 释放资源
        inputStream.close();
        inputStream = null;
        urlConnection.disconnect();
        JSONObject jsonUserObject = new JSONObject(jsonUserStr);
        return jsonUserObject;
    }
}
